package com.lsu.command.experiment;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体的主体类
 *
 * @Author wang suo
 * @Date 2020/10/21 0021 15:11
 * @Version 1.0
 */
public class ConcreteSubject implements ConcreteInvoker, Subject {

    private List<Observer> observers;

    ConcreteSubject() {
        this.observers = new ArrayList<>();
    }

    @Override
    public void notifyObservers(Integer n, Integer x, Integer y) {
        for (Observer observer : observers) {
            observer.update(n, x, y);
        }
    }

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void deleteObserver(Observer observer) {
        observers.remove(observer);
    }
}
